package com.xiaomi.back.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xiaomi.back.service.bill.BillBackService;
import com.xiaomi.back.service.billdetailed.impl.BilldetaildeServiceImpl;
import com.xiaomi.pojo.Bill;
import com.xiaomi.pojo.Billdetailed;
import com.xiaomi.pojo.Commoditys;
import com.xiaomi.util.Todaytime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
public class BilldetailedController {
    @Autowired
    private BilldetaildeServiceImpl billdetaildeService;
    @Autowired
    private BillBackService billBackService;


    //查看今日销售额
    @RequestMapping("/DailySales")
    public String DailySales(@RequestParam(defaultValue = "1") int currentPageNo,Model model){
        double price=billdetaildeService.DailySales(Todaytime.Todaytime());
        model.addAttribute("price",price);

        PageHelper.startPage(currentPageNo, 10);
        List<Bill> billList=billdetaildeService.getDayOrder(Todaytime.Todaytime());
        PageInfo<Bill>page=new PageInfo<>(billList);

        model.addAttribute("page",page);
        return "back/Order/price";
    }

    //查看订单
    @RequestMapping("/OrderAll")
    public String OrderAll(@RequestParam(defaultValue = "1") int currentPageNo, Model model) {

        //设置当前页码和几条数据
        PageHelper.startPage(currentPageNo, 10);
        //获取订单集合
        List<Bill> billList = billdetaildeService.GetBIll();
        PageInfo<Bill> page = new PageInfo<>(billList);

        model.addAttribute("page", page);

        return "back/Order/orderlist";
    }

    //bid  查看订单详情
    @RequestMapping("/back_billInfo/{bid}")
    public String GetBillInfo(@PathVariable("bid") String bid,Model model){
        Bill bill=billBackService.getBid(bid);
        model.addAttribute("bill",bill);
        return "back/Order/billinfo";
    }

    //进入订单发货页
    @RequestMapping("/toOrderInfo/{bid}")
    public String toOrderInfo(@PathVariable("bid")String bid,Model model){
        model.addAttribute("bid",bid);
        return "back/Order/OrderFrom";
    }

    //点击发货 /取消订单
    @RequestMapping("/UseOrder")
    public String UserOrder(String bid,int state,Model model){
        int result=billBackService.UpOrderState(state,bid);
        return "back/Order/orderList";
    }

    //订单按类型 模糊查询
    @RequestMapping("/getOrderClass")
    public String getOrderClass(@RequestParam(defaultValue = "1") int currentPageNo, Model model, @RequestParam("name") String comname,@RequestParam(defaultValue = "0") int lx) {

        PageHelper.startPage(currentPageNo, 10);
        List<Bill>billList=billdetaildeService.getOrder(lx,comname);

        PageInfo<Bill>page=new PageInfo<>(billList);
        model.addAttribute("page",page);
        model.addAttribute("name",comname);
        model.addAttribute("lx",lx);
        return "back/Order/OrderFind";
    }



}
